<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {

    public function index(){

        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $StrSqlHotNew1 = "select a.id,a.title,a.url,a.class,a.iscolor,hlc.classname,a.[time]  from (select Top 1 id,title,url,class,[time],iscolor from hot_list where isColor=1 and area_name='".C("APP_URL_AREA")."'  Union All select Top 3 id,title,url,class,[time],iscolor from hot_list where isColor <> 1 and area_name='".C("APP_URL_AREA")."'  order by [time] desc) as a LEFT JOIN hot_list_class hlc ON hlc.id = a.class order by a.iscolor desc,a.[time] desc";
        $DataHotList1 = $Model->query( $StrSqlHotNew1 );

        $StrIds = "";
        foreach ($DataHotList1 as $k => $v) {
            if ($StrIds == "" ){
                $StrIds = $DataHotList1[$k]['id'];
            }else{
                $StrIds = $StrIds.",". $DataHotList1[$k]['id'];
            }
        }
        $StrSqlHotNew2 = "select a.id,a.title,a.url,a.class,a.iscolor,hlc.classname,a.[time] from (select Top 1 id,title,url,class,[time],iscolor from hot_list where isColor=1 and area_name='".C("APP_URL_AREA")."'  And Id Not in(".$StrIds.") Union All select Top 3 id,title,url,class,[time],iscolor from hot_list where isColor <> 1 and area_name='".C("APP_URL_AREA")."'  And Id Not in(".$StrIds.") order by [time] desc) as a LEFT JOIN hot_list_class hlc ON hlc.id = a.class order by a.iscolor desc,a.[time] desc";
        $DataHotList2 = $Model->query($StrSqlHotNew2);

        //今日要闻
        $DataHotList = array_merge_recursive($DataHotList1,$DataHotList2);

        //幻灯片
        $StrSqlUniAd = "Select Note,PicPath,Url,Width,Height,Stf,bg_link,stype From Uni_Ad Where SType in ('index_huandeng_1','index_huandeng_2','index_huandeng_3','index_huandeng_4','index_huandeng_5') and area_name='".C("APP_URL_AREA")."' and isshow=1 order by orders";
        $DataUniAd = $Model->query( $StrSqlUniAd );

        //今日焦点
        $StrSqlDayArt="Select Top 10 Title,ID,Keywords,ArtDescription,Images,ClassID,ClassName,CONVERT(varchar(100), DateAndTime, 120) as DateAndTime  From Uni_Article Where ClassID='0443013974'  and area_name='".C("APP_URL_AREA")."' Order By IsTop Desc,Id Desc";
        $DataDayArt = $Model->query( $StrSqlDayArt );

        //汽车资讯
        $DataCarNews = $this ->getNewsList("car",10);
        //汽车优惠
        $DataCarYouhui = $this ->getNewsList("youhui",10);

        //房产咨询
        $DataHouseNews = $this ->getNewsList("house",10);


        $this->DataDayArt       = $DataDayArt;
        $this->DataUniAd        = $DataUniAd;
        $this->DataHotList      = $DataHotList;
        $this->DataCarNews      = $DataCarNews;
        $this->DataCarYouhui    = $DataCarYouhui;
        $this->DataHouseNews    = $DataHouseNews;
        $this->display();

//        $serverName = "122.227.164.113";
//        $uid = "sxol";
//        $pwd = "dfdwerwerweradfw3erdwu234%34563445q123sadf";
//
//        $connectionInfo = array("UID"=>$uid,"PWD"=>$pwd,"Database"=>"sxol");
//
//        $conn = sqlsrv_connect( $serverName,$connectionInfo);
//        if( $conn == false)
//        {
//            echo "连接失败！";
//            die( print_r( sqlsrv_errors(), true));
//        }
//
//        $query = sqlsrv_query($conn, "select top 8 id,title from hot_list");
//
//        while($row = sqlsrv_fetch_array($query)){
//            echo $row['id']."######".$row['title']."######"."<br/>";
//        }

     }

     private  function getNewsList($stype,$topnum){
         $Model = new Model();
        if($stype == "house"){
            $sqlNews = "select top ".$topnum." Tid,Title,Id , CONVERT(varchar(100), InputDate, 120) as InputDate from [fy_house].[dbo].[fy_info] where area_name='".C(APP_URL_AREA)."' order by id desc";
        }else{
            if($stype == "car"){
                $wh="'003271307','0344934872','093864742','050510977','0512114629','0584076283','0585365118','0405444409','0371555104','0374394086','039237296','041539940','0425977757','0331920923','0365829163','0404340614','0411677066','0312431502','0314667934','0351340488','0354638464','0193953301','0201031889','0193066579','0553117081','0162960445','0351929750','042191951','046670271','025854482','0445947319'";
            }elseif($stype == "youhui"){
                $wh="'093864742'";
            }elseif ($stype == "travel"){
                $wh="'021069489','025443311','03718218','033816840','04235056','0417105655','0392424207','082944972','0363212734','0374075098','0382586310','0385325291','0401482889','0403090878','0404698868','0414108489','0413651318','0415083942','042554541','0422162531','0423457764','0424726439','043296745','0464368190'";
            }elseif($stype == "money"){
                $wh="'0482468393','0483477428','0484792987','0491096962','0491988640','050362169','0501116164','0502081284','0503265392','0504310587','0505159872','0512106297','0511210910','0512217842','0514112323','0515258748','052261551','0521445659','0522299654','0523339847','0531105386'";
            }elseif($stype == "chaoliu"){
                $wh="'044142761','042924233','0371146431','041955850'";
            }elseif($stype == "meishi"){
                $wh="'2014928171','0552472092'";
            }elseif($stype == "tiyucaipiao"){
                $wh="'2014928173','2014928175'";
            }elseif($stype =="qinggan" ){
                $wh="'029999371','0561254645'";
            }
            $sqlNews = "Select Top ".$topnum." Title,ID,Keywords,ArtDescription,Images,ClassID,ClassName,CONVERT(varchar(100), DateAndTime, 120) as DateAndTime From Uni_Article Where area_name='".C(APP_URL_AREA)."' and ClassID in(".$wh.") ".$wh1." Order By Id Desc";
        }

         $DataNewsList = $Model->query( $sqlNews );
         return $DataNewsList;
    }

    public function article($id){
        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $Model->execute("update Uni_Article set Hits=Hits+1 where id=".$id);

        $StrSqlUniArt = "select *,CONVERT(varchar(100), DateAndTime, 120) as DateAndTime from Uni_Article where id = ".$id." ORDER BY id desc";
        $DataUniArt = $Model->query( $StrSqlUniArt );

        $nav = array('Title1' => "首页", 'Id1' => "#",'Title2' =>  $DataUniArt[0]["ClassName"],'Id2' =>  $DataUniArt[0]["ClassID"]);

        $this->nav = array($nav);
        $this->DataUniArt = $DataUniArt;
        $this->display();
    }
}